home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17123 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  6.1 KB

  1. Path: prairienet.org!wemccaug
  2. From: wemccaug@prairienet.org (Wendy E. McCaughrin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: What Should An Exception Handling Do? -- Clarification of rules
  5. Date: 13 Apr 1996 23:25:37 GMT
  6. Organization: University of Illinois at Urbana
  7. Message-ID: <4kpd5h$17k@vixen.cso.uiuc.edu>
  8. References: <vwjvijer5gj.fsf@osfb.aber.ac.uk> <vwjg2ao6hqp.fsf@osfb.aber.ac.uk>
  9. Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
  10. NNTP-Posting-Host: firefly.prairienet.org
  11.  
  12.  
  13. In a previous article, pcg@aber.ac.uk (Piercarlo Grandi) says:
  14.  
  15. >>>> On Tue, 2 Apr 1996 15:47:22 GMT, shang@corp.mot.com (David L. Shang)
  16. >>>> said:
  17. >
  18. >shang> In article <vwjg2ao6hqp.fsf@osfb.aber.ac.uk> pcg@aber.ac.uk
  19. >shang> (Piercarlo Grandi) writes:
  20. >
  21. >pcg> Therefore exception handling reduces to simply providing a mechanism by
  22. >pcg> which the *author* of a code segment provides a mechanism by which the
  23. >pcg> *user* of that code segment can specify additional cases, as for example
  24.  
  25. sjm> No. 'exception handling' is a mechanism to provide handlers for
  26.      exceptions, written by other authors, not the poor end-user.
  27.      Besides, if they could add more cases of exceptions, this im-
  28.      plies the code isn't finished yet -- is this interpretive code?
  29.  
  30. >pcg> in:
  31. >
  32. >pcg> float sqrt(float n)
  33. >pcg> {
  34. >pcg>   if
  35. >pcg>     n > 0 -> ...;
  36. >pcg>     [] n == 0 -> return 0;
  37. >pcg>     [] n < 0 -> return sqrt_negative(n);
  38. >pcg>   fi
  39. >pcg> }
  40. >
  41. >pcg> where the only difficulty is that sqrt_negative must be dynamically
  42. >pcg> scoped instead of statically scoped, for it must be redefinable by
  43. >pcg> the *user* of the procedure.
  44.  
  45. sjm> Dijkstra's guarded-command language finally made it to comp.lang!
  46.      So here must be where you are referring to addition of a new case
  47.      to test (n < 0) and then providing your handler for it -- so in
  48.      fact, the code was completed but not compiled: would that we all
  49.      had such easy access to the source.
  50. >
  51. >pcg> This again means that termination is the only possible outcome for
  52. >pcg> this case too.
  53.  
  54.  sjm> How so? You returned, didn't you? Let's get clear on this 
  55.       "termination vs. resumption" semantics: it only means you
  56.       branch instead of call, i.e., you pass control to some
  57.       handling mechanism with no provision for return.
  58.  
  59. >
  60. >shang> Termination? When you execute:
  61. >
  62. >shang>     return sqrt_negative(n)
  63. >
  64. >shang> first, you call "sqrt_negative" to get the result, then you do
  65. >shang> return to terminate. It is not the case that you first terminate
  66. >shang> then you call "sqrt_negative".shang> go back.
  67. >
  68. >This is just a low level, mechanical view of
  69. >exceptions/termination/resumption, as indeed demonstrated by your
  70. >subsequent example, which is nothing but an assembler-like expansion of
  71. >what I had written above:
  72.  
  73.  sjm> "...just a low level, mechanical view...": aren't you confusing
  74.       interrupt-handling with exception-handling?
  75. >
  76. >shang> Once your terminate, you can never If I write code like:
  77. >
  78. >shang>      float sqrt(float n)
  79. >shang>      {
  80. >shang>        if
  81. >shang>           n > 0 -> ...;
  82. >shang>        [] n == 0 -> return 0;
  83. >shang>        [] n < 0 -> { n1= sqrt_negative(n); return n1; }
  84. >shang>        fi
  85. >shang>      }
  86. >
  87. >shang> Is the program terminated
  88. >
  89. >Why should one terminate the _program_? Exception handling's purpose is
  90. >precisely not to terminate the program, but to allow it to continue,
  91. >even if on a different path.
  92.  
  93.  sjm> I would in part agree, but a fuller statement of purpose would be:
  94.       "exception handling's purpose is to avoid the unpleasantness of
  95.       abnormal termination whenever possible, but otherwise to exit
  96.       gracefully with a fully descriptive diagnostic for termination".
  97.  
  98. >
  99. >When we are talking of termination/continuation semantics, we are
  100. >talking about the termination/continuation of the bit of code that had
  101. >the problem, not that of the program (or even that of the containing
  102. >scope, I would say).
  103. >
  104. >shang> at the point of calling "sqrt_negative"?  This embedded exception
  105. >shang> handler exactly provides a resumption semantics,
  106. >
  107. >Not at all: for the 'if-fi' is not resumed/continued in any way.
  108. >
  109. >Actually if you agree, as you logically must, that an "exception" is a
  110. >misnomer for the case where a partial function is applied to a value
  111. >outside its codomain, then talking about "exception handlers" and
  112. >termination and continuation does not mean much: the only thing that
  113. >matter is that the partial function is not continued, and that another
  114. >bit of code is used.
  115. >
  116. >The advocates of continuation semantics think that it makes sense
  117. >because they imagine it is possible to make the exception handler wiggle
  118. >things so that the current state of the computation is changed to one
  119. >that *is* in codomain of the ``failing'' partial function; for example
  120. >if on reading one gets EOF on the current volume, the exception handler
  121. >can mount another volume, and on resumption the EOF is gone and
  122. >everything is OK.
  123. >
  124. >But I'd regard this a terrible use of "exception handling", for there is
  125. >no need to use the machinery of dynamic binding in this case, because
  126. >what happens on EOF is not something that cannot be designed in at the
  127. >time the rest of the code is written; in fact essentially all the uses
  128. >of continuation sematics amount to using exception handling instead of a
  129. >'case' or an 'if' with more branches.
  130. >
  131. >shang> which, according to your previous analysis, is the only case that
  132. >shang> exception handling makes any sense(?).
  133. >
  134. >Perhaps we are using "termination" in a different sense: to me in a
  135. >semantic sense, where the current computation simply cannot progress
  136. >because it is a partial function applied to a value outside its
  137. >codomain. If a partial function is applied outside its codomain, then it
  138. >simply *cannot* be continued/resumed/...
  139. >
  140. >You are instead perhaps thinking of non-local control transfers, as in:
  141. >termination semantics for exceptions *necessarily* involve a non local
  142. >control transfer.
  143. >
  144. >To me the issue of exception handling and non local control transfers
  145. >are totally unrelated and independent; not necessarily an exception
  146. >handler shall 'longjmp'/'throw'/... outside the current function. What
  147. >in any case *must* happen is that the current computation is not
  148. >continued, for it cannot continue.
  149. >
  150.  
  151.